package com.amiu.util;

import org.apache.shiro.crypto.hash.SimpleHash;

public class PasswordHelper {
	//默认加密算法
	private static String defaultAlgorithmName = "md5";
	//默认加密次数
	private static int defaultHashIterations = 1; 
	
	public static String encryptPassword(String algorithmName,int hashIterations,String password,String salt){
        /*调用org.apache.shiro.crypto.hash.SimpleHash.SimpleHash(String algorithmName, Object source, Object salt, int hashIterations)
         * 构造方法实现盐值加密  String algorithmName 为加密算法 支持md5 base64 等*/
        SimpleHash sh = new SimpleHash(algorithmName, password, salt, hashIterations);
        //打印最终结果
        return sh.toHex();
	}
	
	public static String encryptPassword(int hashIterations,String password,String salt){
	      return encryptPassword(defaultAlgorithmName, hashIterations, password, salt);
	}
	
	public static String encryptPassword(String algorithmName,String password,String salt){
        return encryptPassword(algorithmName, defaultHashIterations, password, salt);
	}
	
	public static String encryptPassword(String password,String salt){
        return encryptPassword(defaultAlgorithmName, password, salt);
	}

	
	public static void main(String[] args) {
		System.out.println(encryptPassword("123", "mini"));
		System.out.println(encryptPassword(2, "123", "mini"));
		String pwdWithSalt = StandardPasswordHelper.encryptPassword("123",
				"mini");
		System.out.println(pwdWithSalt);
	}
}
